use std::process::Command;

#[derive(serde::Deserialize)]
pub struct NotificationParams {
    title: String,
    body: String,
    icon: String,
}

#[tauri::command]
pub fn show_notification(app: tauri::AppHandle,params: NotificationParams) {
    use tauri_plugin_notification::NotificationExt;
    app.notification()
        .builder()
        .title(params.title)
        .body(params.body)
        .icon(params.icon)
        .show()
        .expect("Notification error");
}

#[tauri::command]
pub fn play_sound(app: tauri::AppHandle) -> Result<(), String> {
     #[cfg(target_os = "windows")]
    {
        // Windows 系统使用 powershell 播放声音
        Command::new("powershell")
           .args(["-Command", r"[system.media.systemsounds]::beep.play()"])
           .spawn()
           .map_err(|e| e.to_string())?;
    }

    #[cfg(target_os = "macos")]
    {
        // macOS 系统使用 afplay 播放声音
        Command::new("afplay")
           .args(["/System/Library/Sounds/Ping.aiff"])
           .spawn()
           .map_err(|e| e.to_string())?;
    }

    #[cfg(target_os = "linux")]
    {
        // Linux 系统使用 paplay 播放声音
        Command::new("paplay")
           .args(["/usr/share/sounds/freedesktop/stereo/complete.oga"])
           .spawn()
           .map_err(|e| e.to_string())?;
    }

    Ok(())
}